package com.geccocrawler.socks5.config;

import java.util.Properties;

import com.geccocrawler.socks5.ProxyServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 配置
 *
 * @author zhengpin
 * @date 2022/09/09
 */
public class Config {

    private static final Logger logger = LoggerFactory.getLogger(ProxyServer.class);

    private int port = 11080;

    private boolean auth = false;

    private boolean logging = true;

    private int readerIdleTime = 3;

    private int writerIdleTime = 30;

    private int allIdleTime = 0;

    public static Config loadProperties() {
        Config config = new Config();
        try {
            Properties properties = new Properties();
            properties.load(ProxyServer.class.getResourceAsStream("/config.properties"));
            config.port = Integer.parseInt(properties.getProperty("port"));
            config.auth = Boolean.parseBoolean(properties.getProperty("auth"));
            config.readerIdleTime = Integer.parseInt(properties.getProperty("idle-time.reader"));
            config.writerIdleTime = Integer.parseInt(properties.getProperty("idle-time.writer"));
            config.allIdleTime = Integer.parseInt(properties.getProperty("idle-time.all"));
        } catch (Exception e) {
            logger.warn("load config.properties error!");
        }
        return config;
    }

    public int getPort() {
        return port;
    }

    public boolean isAuth() {
        return auth;
    }

    public boolean isLogging() {
        return logging;
    }

    public int getReaderIdleTime() {
        return readerIdleTime;
    }

    public int getWriterIdleTime() {
        return writerIdleTime;
    }

    public int getAllIdleTime() {
        return allIdleTime;
    }

    @Override
    public String toString() {
        return "Config{" + "port=" + port + ", auth=" + auth + ", logging=" + logging + ", readerIdleTime="
            + readerIdleTime + ", writerIdleTime=" + writerIdleTime + ", allIdleTime=" + allIdleTime + '}';
    }
}
